using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace LMSData
{
	/// <summary>
	/// Strongly-typed collection for the AssessmentItem class.
	/// </summary>
	[Serializable]
	public partial class AssessmentItemCollection : ActiveList<AssessmentItem, AssessmentItemCollection> 
	{	   
		public AssessmentItemCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the AssessmentItem table.
	/// </summary>
	[Serializable]
	public partial class AssessmentItem : ActiveRecord<AssessmentItem>
	{
		#region .ctors and Default Settings
		
		public AssessmentItem()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public AssessmentItem(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public AssessmentItem(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public AssessmentItem(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("AssessmentItem", TableType.Table, DataService.GetInstance("LMS"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarAssessmentItemID = new TableSchema.TableColumn(schema);
				colvarAssessmentItemID.ColumnName = "AssessmentItemID";
				colvarAssessmentItemID.DataType = DbType.Int32;
				colvarAssessmentItemID.MaxLength = 0;
				colvarAssessmentItemID.AutoIncrement = true;
				colvarAssessmentItemID.IsNullable = false;
				colvarAssessmentItemID.IsPrimaryKey = true;
				colvarAssessmentItemID.IsForeignKey = false;
				colvarAssessmentItemID.IsReadOnly = false;
				colvarAssessmentItemID.DefaultSetting = @"";
				colvarAssessmentItemID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAssessmentItemID);
				
				TableSchema.TableColumn colvarAssessmentID = new TableSchema.TableColumn(schema);
				colvarAssessmentID.ColumnName = "AssessmentID";
				colvarAssessmentID.DataType = DbType.Int32;
				colvarAssessmentID.MaxLength = 0;
				colvarAssessmentID.AutoIncrement = false;
				colvarAssessmentID.IsNullable = false;
				colvarAssessmentID.IsPrimaryKey = false;
				colvarAssessmentID.IsForeignKey = true;
				colvarAssessmentID.IsReadOnly = false;
				colvarAssessmentID.DefaultSetting = @"";
				
					colvarAssessmentID.ForeignKeyTableName = "Assessment";
				schema.Columns.Add(colvarAssessmentID);
				
				TableSchema.TableColumn colvarItemText = new TableSchema.TableColumn(schema);
				colvarItemText.ColumnName = "ItemText";
				colvarItemText.DataType = DbType.String;
				colvarItemText.MaxLength = 2147483647;
				colvarItemText.AutoIncrement = false;
				colvarItemText.IsNullable = true;
				colvarItemText.IsPrimaryKey = false;
				colvarItemText.IsForeignKey = false;
				colvarItemText.IsReadOnly = false;
				colvarItemText.DefaultSetting = @"";
				colvarItemText.ForeignKeyTableName = "";
				schema.Columns.Add(colvarItemText);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["LMS"].AddSchema("AssessmentItem",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("AssessmentItemID")]
		public int AssessmentItemID 
		{
			get { return GetColumnValue<int>("AssessmentItemID"); }

			set { SetColumnValue("AssessmentItemID", value); }

		}

		  
		[XmlAttribute("AssessmentID")]
		public int AssessmentID 
		{
			get { return GetColumnValue<int>("AssessmentID"); }

			set { SetColumnValue("AssessmentID", value); }

		}

		  
		[XmlAttribute("ItemText")]
		public string ItemText 
		{
			get { return GetColumnValue<string>("ItemText"); }

			set { SetColumnValue("ItemText", value); }

		}

		
		#endregion
		
		
		#region PrimaryKey Methods
		
		public LMSData.AssessmentResponseCollection AssessmentResponseRecords()
		{
			return new LMSData.AssessmentResponseCollection().Where(AssessmentResponse.Columns.AssessmentItemID, AssessmentItemID).Load();
		}

		#endregion
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a Assessment ActiveRecord object related to this AssessmentItem
		/// 
		/// </summary>
		public LMSData.Assessment Assessment
		{
			get { return LMSData.Assessment.FetchByID(this.AssessmentID); }

			set { SetColumnValue("AssessmentID", value.AssessmentID); }

		}

		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(int varAssessmentID,string varItemText)
		{
			AssessmentItem item = new AssessmentItem();
			
			item.AssessmentID = varAssessmentID;
			
			item.ItemText = varItemText;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varAssessmentItemID,int varAssessmentID,string varItemText)
		{
			AssessmentItem item = new AssessmentItem();
			
				item.AssessmentItemID = varAssessmentItemID;
				
				item.AssessmentID = varAssessmentID;
				
				item.ItemText = varItemText;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string AssessmentItemID = @"AssessmentItemID";
			 public static string AssessmentID = @"AssessmentID";
			 public static string ItemText = @"ItemText";
						
		}

		#endregion
	}

}

